import type { TableColumnData } from '@arco-design/web-vue'
import { computed, ref } from 'vue'
import { useCommentStore } from '../stores/commentStore'
import { useUserStore } from '@/stores/user'

export function useCommentTable() {
  // const { data, isLoading } = useSearchUser({ role: Role.Student })
  const isLoading = ref(false)
  const { comments } = useCommentStore()
  const userStore = useUserStore()

  return {
    isLoading,
    columns: [
      {
        title: '课题ID',
        dataIndex: 'issueID',
        width: 100,
        align: 'center'
      },
      {
        title: '信息',
        dataIndex: 'message'
      },
      {
        title: '发送者学/工号',
        width: 140,
        dataIndex: 'publisherID',
        slotName: 'publisherID'
      },
      {
        title: '发送者',
        dataIndex: 'publisher',
        width: 140,
        align: 'center'
      },
      {
        title: '回复',
        width: 140,
        align: 'center',
        slotName: 'action',
        fixed: 'right'
      }
    ] as const satisfies TableColumnData[],
    comments: computed(() =>
      comments.value.filter(({ publisherID, targetID }) =>
        [publisherID, targetID].includes(userStore.user.username)
      )
    )
  }
}
